﻿#include "FITKAbaqusAdaptorOutputHistory.h"
#include "InpKeyLineSpliter.h"
#include "FITKAbaqusINPReader.h"
#include "FITKAbaqusINPWriter.h"
#include "FITK_Kernel/FITKCore/FITKEnumTransformer.hpp"
#include "FITK_Component/FITKAbaqusData/FITKDataCase.h"
#include "FITK_Component/FITKAbaqusData/FITKAbaqusPart.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaAssembly.h"
#include "FITK_Interface/FITKInterfaceStructural/FITKAbaHistoryOutput.h"
#include "FITK_Interface/FITKInterfaceModel/FITKModelSet.h"
#include "FITK_Interface/FITKInterfaceModel/FITKComponentManager.h"

//set集合每行不得超过16个，INP准则
#define SETCOUNT 16

//命名空间
namespace IO
{
    QString FITKAbaqusAdaptorOutputHistory::getAdaptorClass()
    {
        return "IO::FITKAbaqusAdaptorOutputHistory";
    }

    void FITKAbaqusAdaptorOutputHistory::setCaseData(AbaqusData::FITKDataCase* caseData)
    {
        _caseData = caseData;
        tool.setCaseData(_caseData);
    }

    void FITKAbaqusAdaptorOutputHistory::setStepData(Interface::FITKAbaAbstractStep * stepData)
    {
        if (stepData == nullptr) return;
        _stepData = stepData;
        //判断类型是否为显示分析
        _isExplicit = stepData->getStepType() == Interface::FITKAbaAbstractStep::FITKAbaStepType::DynamicExplicit;
    }

    bool FITKAbaqusAdaptorOutputHistory::adaptR()
    {
        _outputData = dynamic_cast<Interface::FITKAbaHistoryOutput*>(_dataObj);
        if (!_outputData || !_reader || !_caseData) return false;
        //校验信息
        //QString line = _reader->previousLine();
        //if (!line.toLower().contains("output")) return false;
        //回退一行 处理关键字信息 
        _reader->backLine();
        //_outputData->setDataObjectName(QString::number(_outputData->getCreatedStep()));
        ////互斥参数的最后一个 其余两个为field、history
        //QString diagnostics = s["diagnostics"];
        ////共同的可选参数
        //QString matName = s["name"];
        //_outputData->setDataObjectName(matName);
        ////Standard下的可选参数
        //QString frequency = s["frequency"];
        //QString modeList = s["mode list"];
        //QString numberInterval = s["number interval"];
        //QString timeMarks = s["time marks"];
        //QString timePoints = s["time points"];
        bool isR;
        while (!_reader->atEnd())
        {
            QString line = _reader->readLine();
            //退出条件
            if (line.startsWith("**") || !line.toLower().contains("output")) return true;
            isR = false;
            InpKeyLineSpliter s(line, _reader);
            QString sH = s.getHeader().toLower();
            if (s.hasKey("history"))
            {
                //isR = _isExplicit ? readExplicitHistory() : readStandardHistory();
                isR = readExplicitHistory();
            }
            else if (sH == "node output")
            {
                isR = readNodeOutput(line);
            }
            else if (sH == "contact output")
            {
                isR = readContactOutput(line);
            }
            else if (sH == "element output")
            {
                isR = readElementOutput(line);
            }
            else if (sH == "integrated output")
            {
                //isR = readIntegratedOutput(line);暂时没有此关键字
            }
            else if (sH == "incrementation output")
            {
                isR = readIncrementationOutput(line);
            }
            else if (sH == "energy output")
            {
                isR = readEnergyOutput(line);
            }

            if (!isR)
            {
                _reader->consoleMessage(3, "Read Output Error ");
                return false;
            }
        }
        return isR;
    }

    bool FITKAbaqusAdaptorOutputHistory::adaptW()
    {
        _outputData = dynamic_cast<Interface::FITKAbaHistoryOutput*>(_dataObj);
        if (!_outputData || !_writer || !_caseData) return false;
        bool isW = true;

        isW &= writeExplicitHistory();

        //variable
        auto v = _outputData->getSelectMode();
        QString variable = getVariableString(v);
        bool wOutput = !variable.isEmpty() && _outputData->getDomain() == Interface::FITKAbaOutputVariable::OutputDomain::WholeModel;
        if (!wOutput)
        {
            isW &= writeNodeOutput();
            isW &= writeElementOutput();
            isW &= writeContactOutput();
            //isW &= writeIntegratedOutput();
            isW &= writeIncrementationOutput();
            isW &= writeEnergyOutput();
        }
        //写出
        return isW;
    }

    bool FITKAbaqusAdaptorOutputHistory::readContactOutput(QString line)
    {
        //关键字验证
        if (!line.toLower().startsWith("*contact output")) return false;
        InpKeyLineSpliter s(line, _reader);
        //Explicit类型 Standard类型 共有参数
        QString variable = s["variable"];
        //Standard可选参数
        QString master = s["master"];
        QString nset = s["nset"];
        QString slave = s["slave"];
        QString surface = s["surface"];

        if (!nset.isEmpty())
        {
            //作用域
            this->setDomain(Interface::FITKModelEnum::FITKModelSetType::FMSNode, nset, false);
        }
        _outputData->clearVariables();
        //输出变量
        _outputData->setSelectMode(getSelectedMode(variable), _outputData->getCreatedStep());

        //暂定一定会有此行
        QString dataline = _reader->readLine();
        if (dataline.startsWith("*"))return false;
        auto pv = dataline.split(',');

        for (int i = 0; i < pv.size(); ++i)
        {
            _outputData->appendVariable(pv[i].trimmed());
        }
        return true;
    }

    bool FITKAbaqusAdaptorOutputHistory::readElementOutput(QString line)
    {
        //关键字验证
        if (!line.toLower().startsWith("*element output")) return false;
        InpKeyLineSpliter s(line, _reader);
        //共有参数
        QString variable = s["variable"];
        QString rebar = s["rebar"];
        //可选参数
        bool isAallsectionpts = s.hasKey("allsectionpts");
        QString directions = s["directions"];
        QString elset = s["elset"];
        bool isExterior = s.hasKey("exterior");
        QString micromechanics = s["micromechanics"];
        QString position = s["position"];

        if (position == "CENTROIDAL")
        {

        }
        else if (position == "NODES")
        {

        }
        //作用域
        this->setDomain(Interface::FITKModelEnum::FITKModelSetType::FMSElem, elset, isExterior);
        _outputData->clearVariables();
        //输出变量
        _outputData->setSelectMode(getSelectedMode(variable), _outputData->getCreatedStep());

        //设置是否包括可用的局部坐标方向
        //_outputData->setIncludeLocalCoordDirWhenAvailable(directions.size() == 3);

        //读取变量并添加
        while (!_reader->atEnd())
        {
            if (_outputData->getSelectMode() !=
                Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::SelectFromListBelow) return true;
            QString dataLine = _reader->readLine();
            if (dataLine.startsWith("*"))
            {
                _reader->backLine();
                return true;
            }
            auto pv = dataLine.split(',');
            if (pv.size() < 1) return false;
            for (int i = 0; i < pv.size(); ++i)
            {
                _outputData->appendVariable(pv[i].trimmed());
            }
        }
        return false;
    }

    bool FITKAbaqusAdaptorOutputHistory::readNodeOutput(QString line)
    {
        //关键字验证
        if (!line.toLower().startsWith("*node output")) return false;
        InpKeyLineSpliter s(line, _reader);
        //共有参数 
        QString variable = s["variable"];
        QString nset = s["nset"];
        //自有参数
        bool global = s.hasKey("global");

        //作用域
        this->setDomain(Interface::FITKModelEnum::FITKModelSetType::FMSNode, nset, false);
        _outputData->clearVariables();
        //输出变量
        _outputData->setSelectMode(getSelectedMode(variable), _outputData->getCreatedStep());

        //读取变量并添加
        while (!_reader->atEnd())
        {
            if (_outputData->getSelectMode() !=
                Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::SelectFromListBelow) return true;
            QString dataLine = _reader->readLine();
            if (dataLine.startsWith("*"))
            {
                _reader->backLine();
                return true;
            }
            auto pv = dataLine.split(',');
            if (pv.size() < 1) return false;
            for (int i = 0; i < pv.size(); ++i)
            {
                _outputData->appendVariable(pv[i].trimmed());
            }
        }
        return false;
    }

    bool FITKAbaqusAdaptorOutputHistory::readIntegratedOutput(QString line)
    {
        //关键字验证
        if (!line.toLower().startsWith("*integrated output")) return false;
        InpKeyLineSpliter s(line, _reader);
        //共有参数
        QString variable = s["variable"];
        //互斥参数
        QString section = s["section"];
        QString surface = s["surface"];
        QString elset = s["elset"];

        if (!section.isEmpty())
        {
            //暂不支持
        }
        else if (!surface.isEmpty())
        {
            //暂不支持
        }
        else if (!elset.isEmpty())
        {
            //作用域
            this->setDomain(Interface::FITKModelEnum::FITKModelSetType::FMSElem, elset, false);
        }
        else
        {
            //error
        }

        //输出变量
        _outputData->setSelectMode(getSelectedMode(variable), _outputData->getCreatedStep());

        //读取变量并添加
        while (!_reader->atEnd())
        {
            if (_outputData->getSelectMode() !=
                Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::SelectFromListBelow) return true;
            QString dataLine = _reader->readLine();
            if (dataLine.startsWith("*"))
            {
                _reader->backLine();
                return true;
            }
            auto pv = dataLine.split(',');
            if (pv.size() < 1) return false;
            for (int i = 0; i < pv.size(); ++i)
            {
                _outputData->appendVariable(pv[i].trimmed());
            }
        }
        return false;
    }

    bool FITKAbaqusAdaptorOutputHistory::readStandardHistory()
    {
        QString line = _reader->previousLine();
        if (!line.toLower().startsWith("*output")) return false;
        //关键字处理
        InpKeyLineSpliter s(line, _reader);

        QString op = s["op"];
        QString timeInterval = s["time interval"];
        QString variable = s["variable"];

        if (!timeInterval.isEmpty())
        {
            int intervalNumber = timeInterval.toInt();
            _outputData->setIntervals(intervalNumber);
        }

        if (variable == "PRESELECT")
        {
            _outputData->setSelectMode(Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::PreselectedDefaults);
        }
        else if (variable == "ALL")
        {
            _outputData->setSelectMode(Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::All);
        }
        else if (!variable.isEmpty())
        {
            _reader->consoleMessage(3, "Read History Output Error " + variable);
            return false;
        }

        return true;
    }

    bool FITKAbaqusAdaptorOutputHistory::readExplicitHistory()
    {
        QString line = _reader->previousLine();
        if (!line.toLower().startsWith("*output")) return false;
        //关键字处理
        InpKeyLineSpliter s(line, _reader);
        //频率类型
        QString frequency = s["frequency"];
        //传感器
        QString sensor = s["sensor"];
        //共用参数 过滤器 目前只有平滑类型
        QString filter = s["fikter"];
        QString op = s["op"];
        QString variable = s["variable"];
        QString timeInterval = s["time interval"];

        if (timeInterval.contains('.')) //每X时间单位
        {
            _outputData->setOutputFrequency(Interface::FITKAbaOutputVariable::OutputFrequency::EvertyXUnitsOfTime);
            double xUnits = timeInterval.toDouble();
            _outputData->setXUnitsOfTime(xUnits);
        }
        else if (!frequency.isEmpty())  //每N时间间隔
        {
            _outputData->setOutputFrequency(Interface::FITKAbaOutputVariable::OutputFrequency::EvertyNIncreaments);
            int intervalNumber = frequency.toInt();
            _outputData->setEvertyNIncrements(intervalNumber);
        }
        else //默认均匀时间间隔 200
        {
            _outputData->setOutputFrequency(Interface::FITKAbaOutputVariable::OutputFrequency::EvenlySpacedTimeIntervals);
            int intervalNumber = frequency.toInt();
            //默认值
            if (intervalNumber == 0) intervalNumber = 200;
            _outputData->setIntervals(intervalNumber);
        }

        //输出变量
        if (!variable.isEmpty())
            _outputData->setSelectMode(getSelectedMode(variable), _outputData->getCreatedStep());
        return true;
    }

    //增量输出
    bool FITKAbaqusAdaptorOutputHistory::readIncrementationOutput(QString line)
    {
        //关键字验证
        if (!line.toLower().startsWith("*incrementation output")) return false;

        //关键字处理
        InpKeyLineSpliter s(line, _reader);
        //参数列表
        QString variable = s["variable"];
        //输出变量
        _outputData->setSelectMode(getSelectedMode(variable), _outputData->getCreatedStep());

        //读取变量并添加
        while (!_reader->atEnd())
        {
            if (_outputData->getSelectMode() !=
                Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::SelectFromListBelow) return true;
            QString dataLine = _reader->readLine();
            if (dataLine.startsWith("*"))
            {
                _reader->backLine();
                return true;
            }
            auto pv = dataLine.split(',');
            if (pv.size() < 1) return false;
            for (int i = 0; i < pv.size(); ++i)
            {
                _outputData->appendVariable(pv[i].trimmed());
            }
        }
        return false;
    }

    bool FITKAbaqusAdaptorOutputHistory::readEnergyOutput(QString line)
    {
        //关键字验证
        if (!line.toLower().startsWith("*energy output")) return false;
        //关键字处理
        InpKeyLineSpliter s(line, _reader);

        QString elset = s["elset"];
        if (!elset.isEmpty())
            this->setDomain(Interface::FITKModelEnum::FITKModelSetType::FMSElem, elset, false);
        QString nset = s["nset"];
        if (!nset.isEmpty())
            this->setDomain(Interface::FITKModelEnum::FITKModelSetType::FMSNode, nset, false);

        //下面两个参数数据结构不支持 显示分析
        //QString pset = s["pre element set"];
        //QString pSection = s["pre section"];

        QString variable = s["variable"];
        _outputData->setSelectMode(getSelectedMode(variable), _outputData->getCreatedStep());
        //读取变量并添加
        while (!_reader->atEnd())
        {
            if (_outputData->getSelectMode() !=
                Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::SelectFromListBelow) return true;
            QString dataLine = _reader->readLine();
            if (dataLine.startsWith("*"))
            {
                _reader->backLine();
                return true;
            }
            auto pv = dataLine.split(',');
            if (pv.size() < 1) return false;
            for (int i = 0; i < pv.size(); ++i)
            {
                _outputData->appendVariable(pv[i].trimmed());
            }
        }

        return true;
    }

    bool FITKAbaqusAdaptorOutputHistory::writeStandardHistory()
    {
        auto stream = _writer->getStream();
        *stream << "*Output, history";

        if (_outputData->getSelectMode() == Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::PreselectedDefaults)
        {
            *stream << QString(",variable=%1").arg("PRESELECT");
        }
        else if (_outputData->getSelectMode() == Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::All)
        {
            *stream << QString(",variable=%1").arg("ALL");
        }

        return false;
    }

    bool FITKAbaqusAdaptorOutputHistory::writeExplicitHistory()
    {
        bool isW = true;
        QString output;
        // 写出函数主体
        QTextStream* stream = _writer->getStream();
        output += "*Output, history";
        //variable
        auto v = _outputData->getSelectMode();

        QString variable = getVariableString(v);

        if (!variable.isEmpty() && _outputData->getDomain() == Interface::FITKAbaOutputVariable::OutputDomain::WholeModel)
            output += QString(", %1").arg(variable);

        if (_outputData->getOutputFrequency() == Interface::FITKAbaOutputVariable::OutputFrequency::EvertyNIncreaments)        //每N时间增量
        {
            QString n = _writer->int2String(_outputData->getEveryNIncrements(), 0);
            output += QString(", frequency=%1").arg(n);
        }
        else if (_outputData->getOutputFrequency() == Interface::FITKAbaOutputVariable::OutputFrequency::EvenlySpacedTimeIntervals) //均匀时间间隔
        {
            //200是默认值
            if (_outputData->getIntervals() != 200)
            {
                QString strInterval = _writer->int2String(_outputData->getIntervals(), 0);
                output += QString(", time interval=%1").arg(strInterval);
            }
        }
        else if (_outputData->getOutputFrequency() == Interface::FITKAbaOutputVariable::OutputFrequency::EvertyXUnitsOfTime) //每X时间单位
        {
            QString x = _writer->double2String(_outputData->getXUnitsOfTime(), 9, 0);
            output += QString(", time interval=%1").arg(x);
        }
        *stream << output << endl;
        return isW;
    }

    bool FITKAbaqusAdaptorOutputHistory::writeContactOutput()
    {
        ////共有参数
        //QString nset = s["nset"];
        //QString tracerSet = s["tracer set"];
        // 写出函数主体
        QTextStream* stream = _writer->getStream();
        QString outputString;
        QString nsetName;
        QString variable = getVariableString(_outputData->getSelectMode());

        auto setObj = _outputData->getComponentObj();
        auto modelObj = _outputData->getModelObj();
        nsetName = getSetName(setObj, modelObj);

        outputString += "*Contact Output";
        if (_outputData->getComponentID() != 0 && !nsetName.isEmpty())
            outputString += QString(", nset=%1").arg(nsetName);

        if (!variable.isEmpty())
            outputString += QString(", %1").arg(variable);

        auto varList = _outputData->getSelectedContactVaraiables();
        if (varList.size() > 0)
            *stream << outputString << endl;
        if (isSelectedModelWrite(_outputData->getSelectMode()))
            _writer->writeLineData(varList);
        return true;
    }

    bool FITKAbaqusAdaptorOutputHistory::writeElementOutput()
    {
        ////共有参数
        //QString nset = s["nset"];
        //QString tracerSet = s["tracer set"];
        // 写出函数主体
        QTextStream* stream = _writer->getStream();
        QString outputString;
        QString elsetName;
        QString variable = getVariableString(_outputData->getSelectMode());

        auto setObj = _outputData->getComponentObj();
        auto modelObj = _outputData->getModelObj();
        elsetName = getSetName(setObj, modelObj);

        outputString += "*Element Output";
        if (_outputData->getComponentID() != 0 && !elsetName.isEmpty())
            outputString += QString(", elset=%1").arg(elsetName);

        if (!variable.isEmpty())
            outputString += QString(", %1").arg(variable);

        auto varList = _outputData->getSelectedElementVariables();
        if (varList.size() > 0)
            *stream << outputString << endl;
        if (isSelectedModelWrite(_outputData->getSelectMode()))
            _writer->writeLineData(varList);
        return true;
    }

    bool FITKAbaqusAdaptorOutputHistory::writeNodeOutput()
    {
        ////共有参数
        //QString nset = s["nset"];
        //QString tracerSet = s["tracer set"];
        // 写出函数主体
        QTextStream* stream = _writer->getStream();
        QString outputString;
        QString nsetName;
        QString variable = getVariableString(_outputData->getSelectMode());

        auto setObj = _outputData->getComponentObj();
        auto modelObj = _outputData->getModelObj();
        nsetName = getSetName(setObj, modelObj);

        outputString += "*Node Output";
        //if (_outputData->getExteriorOnly())
        //    outputString += ", exterior";
        if (_outputData->getComponentID() != 0 && !nsetName.isEmpty())
            outputString += QString(", nset=%1").arg(nsetName);

        if (!variable.isEmpty())
            outputString += QString(", %1").arg(variable);

        auto varList = _outputData->getSelectedNodalVariables();
        if (varList.size() > 0)
            *stream << outputString << endl;
        if (isSelectedModelWrite(_outputData->getSelectMode()))
            _writer->writeLineData(varList);
        return true;
    }

    bool FITKAbaqusAdaptorOutputHistory::writeIntegratedOutput()
    {
        QTextStream* stream = _writer->getStream();
        QString outputString;
        QString elsetName;
        QString variable = getVariableString(_outputData->getSelectMode());

        outputString += "*Integrated Output";

        auto setObj = _outputData->getComponentObj();
        auto modelObj = _outputData->getModelObj();
        elsetName = getSetName(setObj, modelObj);

        if (_outputData->getComponentID() != 0 && !elsetName.isEmpty())
            outputString += QString(", elset=%1").arg(elsetName);

        if (!variable.isEmpty())
            outputString += QString(", %1").arg(variable);

        auto varList = _outputData->getSelectedContactVaraiables();
        if (varList.size() > 0)
            *stream << outputString << endl;
        if (isSelectedModelWrite(_outputData->getSelectMode()))
            _writer->writeLineData(varList);
        return true;
    }

    bool FITKAbaqusAdaptorOutputHistory::writeIncrementationOutput()
    {
        QTextStream* stream = _writer->getStream();
        QString outputString;
        QString variable = getVariableString(_outputData->getSelectMode());

        outputString += "*Incrementation Output";

        if (!variable.isEmpty())
            outputString += QString(", %1").arg(variable);

        auto varList = _outputData->getSelectedIncrementationVariables();
        if (varList.size() > 0)
            *stream << outputString << endl;
        if (isSelectedModelWrite(_outputData->getSelectMode()))
            _writer->writeLineData(varList);
        return true;
    }

    bool FITKAbaqusAdaptorOutputHistory::writeEnergyOutput()
    {
        QTextStream* stream = _writer->getStream();
        QString outputString;
        QString variable = getVariableString(_outputData->getSelectMode());
        outputString += "*Energy Output";
        QString setName;
        //获取集合
        auto setObj = _outputData->getComponentObj();
        auto modelObj = _outputData->getModelObj();
        setName = getSetName(setObj, modelObj);

        if (!setName.isEmpty())
        {
            //注释， 暂时只支持elset
            //if (set->getModelSetType() == Interface::FITKModelEnum::FITKModelSetType::FMSNode)
            //	outputString += QString(", nset=%1").arg(setName);
            //if (set->getModelSetType() == Interface::FITKModelEnum::FITKModelSetType::FMSElem)
            outputString += QString(", elset=%1").arg(setName);
        }

        //写出 整个模型 或 点集 或 单元集
        if (!variable.isEmpty())
            outputString += QString(", %1").arg(variable);

        auto varList = _outputData->getSelectedEnergyVariables();
        if (varList.size() > 0)
            *stream << outputString << endl;
        if (isSelectedModelWrite(_outputData->getSelectMode()))
            _writer->writeLineData(varList);

        return true;
    }

    bool FITKAbaqusAdaptorOutputHistory::isSelectedModelWrite(Interface::FITKAbaOutputVariable::OutputVariablesSelectMode mode)
    {
        switch (mode)
        {
        case Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::SelectFromListBelow:
            return true;
        case Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::PreselectedDefaults:
            return false;
        case Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::All:
            return false;
        case Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::EditVariables:
            return true;
        }
        return false;
    }

    Interface::FITKAbaOutputVariable::OutputVariablesSelectMode FITKAbaqusAdaptorOutputHistory::getSelectedMode(QString variable)
    {
        if (variable == "PRESELECT")
        {
            return Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::PreselectedDefaults;
        }
        else if (variable == "ALL")
        {
            return Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::All;
        }
        else if (variable.isEmpty())
        {
            return Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::SelectFromListBelow;
        }
        else
        {
            //错误异常 避免写出的时候调用
            if (_reader == nullptr) return Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::EditVariables;
            _writer->consoleMessage(3, QString("Read Field Output Error,%1 File:%2 Line:%3").arg(variable).arg(__FILE__).arg(__LINE__));

        }
        return Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::EditVariables;
    }

    QString FITKAbaqusAdaptorOutputHistory::getVariableString(Interface::FITKAbaOutputVariable::OutputVariablesSelectMode typeModel)
    {
        QString variable;
        if (typeModel == Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::SelectFromListBelow)
            variable = "";
        else if (typeModel == Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::PreselectedDefaults)
            variable = "variable=PRESELECT";
        else if (typeModel == Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::All)
            variable = "variable=ALL";
        else if (typeModel == Interface::FITKAbaOutputVariable::OutputVariablesSelectMode::EditVariables)
            variable = "";
        return variable;
    }

    bool FITKAbaqusAdaptorOutputHistory::setDomain(Interface::FITKModelEnum::FITKModelSetType type, QString str, bool isExterior)
    {
        bool isOK = false;

        //nset 或者 elset
        if (type != Interface::FITKModelEnum::FITKModelSetType::FMSNone && !str.isEmpty())
        {
            int modelID = -1;
            int setID = tool.getSetIDByName(str, type, modelID);
            if (setID < 1) return false;

            //查询名字为 elset的ID 需要获取set管理器
            _outputData->setModel(modelID);
            _outputData->setComponent(setID);
            _outputData->setDomain(Interface::FITKAbaOutputVariable::OutputDomain::Set);
            isOK = true;
        }
        else//整个模型
        {
            _outputData->setDomain(Interface::FITKAbaOutputVariable::OutputDomain::WholeModel);
            isOK = true;
        }

        return isOK;
    }

    QString FITKAbaqusAdaptorOutputHistory::getSetName(Interface::FITKAbstractModelComponent * comp, Interface::FITKAbstractModel * model)
    {
        QString setName;
        auto setObj = _outputData->getComponentObj();
        if (!setObj) return setName;
        setName = setObj->getDataObjectName();
        setName = setName.contains(' ') ? QString("\"%1\"").arg(setName) : setName;
        auto modelObj = _outputData->getModelObj();
        if (modelObj &&
            setObj->getAbstractModel()->getAbsModelType() == Interface::FITKModelEnum::AbsModelType::AMTMIX &&
            modelObj->getAbsModelType() == Interface::FITKModelEnum::AbsModelType::AssInstance
            )
        {
            QString name = modelObj->getDataObjectName();
            name = name.contains(' ') ? QString("\"%1\"").arg(name) : name;
            setName = name + "." + setName;
        }
        return setName;
    }
}
